#ifndef SOCKETFACTORY_H
#define SOCKETFACTORY_H

#include <QObject>
#include <QList>
#include <QSignalMapper>
#include <QTcpSocket>
#include <QJsonObject>
#include <QJsonDocument>
#include <QDataStream>
#include <QThread>
#include <TranslateJson.h>
#include <AddPlantInfo.h>
#include <ServerLogin.h>
#include <DatasPackaging.h>

class SocketFactory : public QObject
{
    Q_OBJECT
public:
    enum {
        LOGIN  = 1001,
        ADD    = 1002,
        SELECT = 1003,
        AMEND  = 1004,
        UPDATE = 1005,
        EXPORT = 1006,
        DELETE = 1007
    };
    SocketFactory(QObject* parent = 0);
    ~SocketFactory();

signals:
    void sendExportsignal(QMap<int, QList<QList<QVariant>>> m_map, int index);                          //导入数据线程信号
    void sendSelectsignal(QMap<int, QList<QList<QVariant>>> m_map, int index);                          //返回数据列表线程信号
public slots:
    void acceptSocketDescriptor(qintptr SocketDescriptor);                                              //接收socket描述符
    void dispatchSocketInfo(int index);                                                                 //派发客户端的连接
    void socketState(int index);                                                                        //客户端退出并清除list无效客户端
    void clearDatasSize();                                                                              //清除接收数据
    void feedbackExportInfo(bool result, int index);                                                    //导入信息反馈回客户端
    void feedbackSelectResult(const bool result, const QList<QList<QVariant>> m_lists, const int index);//查询数据反馈
private:
    QList<QTcpSocket*>* listSockt;
    QSignalMapper   * mapper;
    QSignalMapper   * SocketDisconnectedSignals;
    TranslateJson translateJson;
    QThread         * m_thread;
    AddPlantInfo    * m_addPlantInfo;
    DatasPackaging  * datapack;
    qint64 sizeDatas;
    QByteArray countDatas;
};

#endif // SOCKETFACTORY_H
